<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>dom_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_testing_dom_test.js.html">dom_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.testing.domTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.testing.domTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.dom&#39;);
<a name="line19"></a>goog.require(&#39;goog.dom.TagName&#39;);
<a name="line20"></a>goog.require(&#39;goog.testing.dom&#39;);
<a name="line21"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line22"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line23"></a>
<a name="line24"></a>var root;
<a name="line25"></a>function setUpPage() {
<a name="line26"></a>  root = goog.dom.getElement(&#39;root&#39;);
<a name="line27"></a>}
<a name="line28"></a>
<a name="line29"></a>function setUp() {
<a name="line30"></a>  root.innerHTML = &#39;&#39;;
<a name="line31"></a>}
<a name="line32"></a>
<a name="line33"></a>function testFindNode() {
<a name="line34"></a>  // Test the easiest case.
<a name="line35"></a>  root.innerHTML = &#39;a&lt;br&gt;b&#39;;
<a name="line36"></a>  assertEquals(goog.testing.dom.findTextNode(&#39;a&#39;, root), root.firstChild);
<a name="line37"></a>  assertEquals(goog.testing.dom.findTextNode(&#39;b&#39;, root), root.lastChild);
<a name="line38"></a>  assertNull(goog.testing.dom.findTextNode(&#39;c&#39;, root));
<a name="line39"></a>}
<a name="line40"></a>
<a name="line41"></a>function testFindNodeDuplicate() {
<a name="line42"></a>  // Test duplicate.
<a name="line43"></a>  root.innerHTML = &#39;c&lt;br&gt;c&#39;;
<a name="line44"></a>  assertEquals(&#39;Should return first duplicate&#39;,
<a name="line45"></a>      goog.testing.dom.findTextNode(&#39;c&#39;, root), root.firstChild);
<a name="line46"></a>}
<a name="line47"></a>
<a name="line48"></a>function findNodeWithHierarchy() {
<a name="line49"></a>  // Test a more complicated hierarchy.
<a name="line50"></a>  root.innerHTML = &#39;&lt;div&gt;a&lt;p&gt;b&lt;span&gt;c&lt;/span&gt;d&lt;/p&gt;e&lt;/div&gt;&#39;;
<a name="line51"></a>  assertEquals(goog.dom.TagName.DIV,
<a name="line52"></a>      goog.testing.dom.findTextNode(&#39;a&#39;, root).parentNode.tagName);
<a name="line53"></a>  assertEquals(goog.dom.TagName.P,
<a name="line54"></a>      goog.testing.dom.findTextNode(&#39;b&#39;, root).parentNode.tagName);
<a name="line55"></a>  assertEquals(goog.dom.TagName.SPAN,
<a name="line56"></a>      goog.testing.dom.findTextNode(&#39;c&#39;, root).parentNode.tagName);
<a name="line57"></a>  assertEquals(goog.dom.TagName.P,
<a name="line58"></a>      goog.testing.dom.findTextNode(&#39;d&#39;, root).parentNode.tagName);
<a name="line59"></a>  assertEquals(goog.dom.TagName.DIV,
<a name="line60"></a>      goog.testing.dom.findTextNode(&#39;e&#39;, root).parentNode.tagName);
<a name="line61"></a>}
<a name="line62"></a>
<a name="line63"></a>function setUpAssertHtmlMatches() {
<a name="line64"></a>  var tag1, tag2;
<a name="line65"></a>  if (goog.userAgent.IE) {
<a name="line66"></a>    tag1 = goog.dom.TagName.DIV;
<a name="line67"></a>  } else if (goog.userAgent.WEBKIT) {
<a name="line68"></a>    tag1 = goog.dom.TagName.P;
<a name="line69"></a>    tag2 = goog.dom.TagName.BR;
<a name="line70"></a>  } else if (goog.userAgent.GECKO) {
<a name="line71"></a>    tag1 = goog.dom.TagName.SPAN;
<a name="line72"></a>    tag2 = goog.dom.TagName.BR;
<a name="line73"></a>  }
<a name="line74"></a>
<a name="line75"></a>  var parent = goog.dom.createDom(goog.dom.TagName.DIV);
<a name="line76"></a>  root.appendChild(parent);
<a name="line77"></a>  parent.style.fontSize = &#39;2em&#39;;
<a name="line78"></a>  parent.style.display = &#39;none&#39;;
<a name="line79"></a>  if (!goog.userAgent.WEBKIT) {
<a name="line80"></a>    parent.appendChild(goog.dom.createTextNode(&#39;NonWebKitText&#39;));
<a name="line81"></a>  }
<a name="line82"></a>
<a name="line83"></a>  if (tag1) {
<a name="line84"></a>    var e1 = goog.dom.createDom(tag1);
<a name="line85"></a>    parent.appendChild(e1);
<a name="line86"></a>    parent = e1;
<a name="line87"></a>  }
<a name="line88"></a>  if (tag2) {
<a name="line89"></a>    parent.appendChild(goog.dom.createDom(tag2));
<a name="line90"></a>  }
<a name="line91"></a>  parent.appendChild(goog.dom.createTextNode(&#39;Text&#39;));
<a name="line92"></a>  if (goog.userAgent.WEBKIT) {
<a name="line93"></a>    root.firstChild.appendChild(goog.dom.createTextNode(&#39;WebKitText&#39;));
<a name="line94"></a>  }
<a name="line95"></a>}
<a name="line96"></a>
<a name="line97"></a>function testAssertHtmlContentsMatch() {
<a name="line98"></a>  setUpAssertHtmlMatches();
<a name="line99"></a>
<a name="line100"></a>  goog.testing.dom.assertHtmlContentsMatch(
<a name="line101"></a>      &#39;&lt;div style=&quot;display: none; font-size: 2em&quot;&gt;&#39; +
<a name="line102"></a>      &#39;[[!WEBKIT]]NonWebKitText&lt;div class=&quot;IE&quot;&gt;&lt;p class=&quot;WEBKIT&quot;&gt;&#39; +
<a name="line103"></a>      &#39;&lt;span class=&quot;GECKO&quot;&gt;&lt;br class=&quot;GECKO WEBKIT&quot;&gt;Text&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&#39; +
<a name="line104"></a>      &#39;&lt;/div&gt;[[WEBKIT]]WebKitText&#39;,
<a name="line105"></a>      root);
<a name="line106"></a>}
<a name="line107"></a>
<a name="line108"></a>function testAssertHtmlMismatchText() {
<a name="line109"></a>  setUpAssertHtmlMatches();
<a name="line110"></a>
<a name="line111"></a>  var e = assertThrows(&#39;Should fail due to mismatched text&#39;, function() {
<a name="line112"></a>    goog.testing.dom.assertHtmlContentsMatch(
<a name="line113"></a>        &#39;&lt;div style=&quot;display: none; font-size: 2em&quot;&gt;&#39; +
<a name="line114"></a>        &#39;[[IE GECKO]]NonWebKitText&lt;div class=&quot;IE&quot;&gt;&lt;p class=&quot;WEBKIT&quot;&gt;&#39; +
<a name="line115"></a>        &#39;&lt;span class=&quot;GECKO&quot;&gt;&lt;br class=&quot;GECKO WEBKIT&quot;&gt;Bad&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&#39; +
<a name="line116"></a>        &#39;&lt;/div&gt;[[WEBKIT]]Extra&#39;,
<a name="line117"></a>        root);
<a name="line118"></a>  });
<a name="line119"></a>  assertContains(&#39;Text should match&#39;, e.message);
<a name="line120"></a>}
<a name="line121"></a>
<a name="line122"></a>function testAssertHtmlMismatchTag() {
<a name="line123"></a>  setUpAssertHtmlMatches();
<a name="line124"></a>
<a name="line125"></a>  var e = assertThrows(&#39;Should fail due to mismatched tag&#39;, function() {
<a name="line126"></a>    goog.testing.dom.assertHtmlContentsMatch(
<a name="line127"></a>        &#39;&lt;span style=&quot;display: none; font-size: 2em&quot;&gt;&#39; +
<a name="line128"></a>        &#39;[[IE GECKO]]NonWebKitText&lt;div class=&quot;IE&quot;&gt;&lt;p class=&quot;WEBKIT&quot;&gt;&#39; +
<a name="line129"></a>        &#39;&lt;span class=&quot;GECKO&quot;&gt;&lt;br class=&quot;GECKO WEBKIT&quot;&gt;Text&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&#39; +
<a name="line130"></a>        &#39;&lt;/span&gt;[[WEBKIT]]Extra&#39;,
<a name="line131"></a>        root);
<a name="line132"></a>  });
<a name="line133"></a>  assertContains(&#39;Tag names should match&#39;, e.message);
<a name="line134"></a>}
<a name="line135"></a>
<a name="line136"></a>function testAssertHtmlMismatchStyle() {
<a name="line137"></a>  setUpAssertHtmlMatches();
<a name="line138"></a>
<a name="line139"></a>  var e = assertThrows(&#39;Should fail due to mismatched style&#39;, function() {
<a name="line140"></a>    goog.testing.dom.assertHtmlContentsMatch(
<a name="line141"></a>        &#39;&lt;div style=&quot;display: none; font-size: 3em&quot;&gt;&#39; +
<a name="line142"></a>        &#39;[[IE GECKO]]NonWebKitText&lt;div class=&quot;IE&quot;&gt;&lt;p class=&quot;WEBKIT&quot;&gt;&#39; +
<a name="line143"></a>        &#39;&lt;span class=&quot;GECKO&quot;&gt;&lt;br class=&quot;GECKO WEBKIT&quot;&gt;Text&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&#39; +
<a name="line144"></a>        &#39;&lt;/div&gt;[[WEBKIT]]Extra&#39;,
<a name="line145"></a>        root);
<a name="line146"></a>  });
<a name="line147"></a>  assertContains(&#39;Should have same styles&#39;, e.message);
<a name="line148"></a>}
<a name="line149"></a>
<a name="line150"></a>function testAssertHtmlMismatchOptionalText() {
<a name="line151"></a>  setUpAssertHtmlMatches();
<a name="line152"></a>
<a name="line153"></a>  var e = assertThrows(&#39;Should fail due to mismatched text&#39;, function() {
<a name="line154"></a>    goog.testing.dom.assertHtmlContentsMatch(
<a name="line155"></a>        &#39;&lt;div style=&quot;display: none; font-size: 2em&quot;&gt;&#39; +
<a name="line156"></a>        &#39;[[IE GECKO]]Bad&lt;div class=&quot;IE&quot;&gt;&lt;p class=&quot;WEBKIT&quot;&gt;&#39; +
<a name="line157"></a>        &#39;&lt;span class=&quot;GECKO&quot;&gt;&lt;br class=&quot;GECKO WEBKIT&quot;&gt;Text&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&#39; +
<a name="line158"></a>        &#39;&lt;/div&gt;[[WEBKIT]]Bad&#39;,
<a name="line159"></a>        root);
<a name="line160"></a>  });
<a name="line161"></a>  assertContains(&#39;Text should match&#39;, e.message);
<a name="line162"></a>}
<a name="line163"></a>
<a name="line164"></a>function testAssertHtmlMismatchExtraActualAfterText() {
<a name="line165"></a>  root.innerHTML = &#39;&lt;div&gt;abc&lt;/div&gt;def&#39;;
<a name="line166"></a>
<a name="line167"></a>  var e = assertThrows(&#39;Should fail due to extra actual nodes&#39;, function() {
<a name="line168"></a>    goog.testing.dom.assertHtmlContentsMatch(&#39;&lt;div&gt;abc&lt;/div&gt;&#39;, root);
<a name="line169"></a>  });
<a name="line170"></a>  assertContains(&#39;Finished expected HTML before&#39;, e.message);
<a name="line171"></a>}
<a name="line172"></a>
<a name="line173"></a>function testAssertHtmlMismatchExtraActualAfterElement() {
<a name="line174"></a>  root.innerHTML = &#39;&lt;br&gt;def&#39;;
<a name="line175"></a>
<a name="line176"></a>  var e = assertThrows(&#39;Should fail due to extra actual nodes&#39;, function() {
<a name="line177"></a>    goog.testing.dom.assertHtmlContentsMatch(&#39;&lt;br&gt;&#39;, root);
<a name="line178"></a>  });
<a name="line179"></a>  assertContains(&#39;Finished expected HTML before&#39;, e.message);
<a name="line180"></a>}
<a name="line181"></a>
<a name="line182"></a>function testAssertHtmlMatchesWithSplitTextNodes() {
<a name="line183"></a>  root.appendChild(goog.dom.createTextNode(&#39;1&#39;));
<a name="line184"></a>  root.appendChild(goog.dom.createTextNode(&#39;2&#39;));
<a name="line185"></a>  root.appendChild(goog.dom.createTextNode(&#39;3&#39;));
<a name="line186"></a>  goog.testing.dom.assertHtmlContentsMatch(&#39;123&#39;, root);
<a name="line187"></a>}
<a name="line188"></a>
<a name="line189"></a>function testAssertHtmlMatchesWithDifferentlyOrderedAttributes() {
<a name="line190"></a>  root.innerHTML = &#39;&lt;div foo=&quot;a&quot; bar=&quot;b&quot; class=&quot;className&quot;&gt;&lt;/div&gt;&#39;;
<a name="line191"></a>
<a name="line192"></a>  goog.testing.dom.assertHtmlContentsMatch(
<a name="line193"></a>      &#39;&lt;div bar=&quot;b&quot; class=&quot;className&quot; foo=&quot;a&quot;&gt;&lt;/div&gt;&#39;, root, true);
<a name="line194"></a>}
<a name="line195"></a>
<a name="line196"></a>function testAssertHtmlMismatchWithDifferentNumberOfAttributes() {
<a name="line197"></a>  root.innerHTML = &#39;&lt;div foo=&quot;a&quot; bar=&quot;b&quot;&gt;&lt;/div&gt;&#39;;
<a name="line198"></a>
<a name="line199"></a>  var e = assertThrows(function() {
<a name="line200"></a>    goog.testing.dom.assertHtmlContentsMatch(
<a name="line201"></a>        &#39;&lt;div foo=&quot;a&quot;&gt;&lt;/div&gt;&#39;, root, true);
<a name="line202"></a>  });
<a name="line203"></a>  assertContains(&#39;Unexpected attribute with name bar in element&#39;, e.message);
<a name="line204"></a>}
<a name="line205"></a>
<a name="line206"></a>function testAssertHtmlMismatchWithDifferentAttributeNames() {
<a name="line207"></a>  root.innerHTML = &#39;&lt;div foo=&quot;a&quot; bar=&quot;b&quot;&gt;&lt;/div&gt;&#39;;
<a name="line208"></a>
<a name="line209"></a>  var e = assertThrows(function() {
<a name="line210"></a>    goog.testing.dom.assertHtmlContentsMatch(
<a name="line211"></a>        &#39;&lt;div foo=&quot;a&quot; baz=&quot;b&quot;&gt;&lt;/div&gt;&#39;, root, true);
<a name="line212"></a>  });
<a name="line213"></a>  assertContains(&#39;Expected to find attribute with name baz&#39;, e.message);
<a name="line214"></a>}
<a name="line215"></a>
<a name="line216"></a>function testAssertHtmlMismatchWithDifferentClassNames() {
<a name="line217"></a>  root.innerHTML = &#39;&lt;div class=&quot;className1&quot;&gt;&lt;/div&gt;&#39;;
<a name="line218"></a>
<a name="line219"></a>  var e = assertThrows(function() {
<a name="line220"></a>    goog.testing.dom.assertHtmlContentsMatch(
<a name="line221"></a>        &#39;&lt;div class=&quot;className2&quot;&gt;&lt;/div&gt;&#39;, root, true);
<a name="line222"></a>  });
<a name="line223"></a>  assertContains(
<a name="line224"></a>      &#39;Expected class was: className2, but actual class was: className1&#39;,
<a name="line225"></a>      e.message);
<a name="line226"></a>}
<a name="line227"></a>
<a name="line228"></a>function testAssertHtmlMatchesWithClassNameAndUserAgentSpecified() {
<a name="line229"></a>  root.innerHTML =
<a name="line230"></a>      &#39;&lt;div&gt;&#39; + (goog.userAgent.GECKO ? &#39;&lt;div class=&quot;foo&quot;&gt;&lt;/div&gt;&#39; : &#39;&#39;) +
<a name="line231"></a>      &#39;&lt;/div&gt;&#39;;
<a name="line232"></a>
<a name="line233"></a>  goog.testing.dom.assertHtmlContentsMatch(
<a name="line234"></a>      &#39;&lt;div&gt;&lt;div class=&quot;foo GECKO&quot;&gt;&lt;/div&gt;&lt;/div&gt;&#39;,
<a name="line235"></a>      root, true);
<a name="line236"></a>}
<a name="line237"></a>
<a name="line238"></a>function testAssertHtmlMatchesWithClassesInDifferentOrder() {
<a name="line239"></a>  root.innerHTML = &#39;&lt;div class=&quot;class1 class2&quot;&gt;&lt;/div&gt;&#39;;
<a name="line240"></a>
<a name="line241"></a>  goog.testing.dom.assertHtmlContentsMatch(
<a name="line242"></a>      &#39;&lt;div class=&quot;class2 class1&quot;&gt;&lt;/div&gt;&#39;, root, true);
<a name="line243"></a>}
<a name="line244"></a>
<a name="line245"></a>function testAssertHtmlMismatchWithDifferentAttributeValues() {
<a name="line246"></a>  root.innerHTML = &#39;&lt;div foo=&quot;b&quot; bar=&quot;a&quot;&gt;&lt;/div&gt;&#39;;
<a name="line247"></a>
<a name="line248"></a>  var e = assertThrows(function() {
<a name="line249"></a>    goog.testing.dom.assertHtmlContentsMatch(
<a name="line250"></a>        &#39;&lt;div foo=&quot;a&quot; bar=&quot;a&quot;&gt;&lt;/div&gt;&#39;, root, true);
<a name="line251"></a>  });
<a name="line252"></a>  assertContains(&#39;Expected attribute foo has a different value&#39;, e.message);
<a name="line253"></a>}
<a name="line254"></a>
<a name="line255"></a>function testAssertHtmlMatchesWhenStrictAttributesIsFalse() {
<a name="line256"></a>  root.innerHTML = &#39;&lt;div foo=&quot;a&quot; bar=&quot;b&quot;&gt;&lt;/div&gt;&#39;;
<a name="line257"></a>
<a name="line258"></a>  goog.testing.dom.assertHtmlContentsMatch(&#39;&lt;div foo=&quot;a&quot;&gt;&lt;/div&gt;&#39;, root);
<a name="line259"></a>}
<a name="line260"></a>
<a name="line261"></a>function testAssertHtmlMatchesForMethodsAttribute() {
<a name="line262"></a>  root.innerHTML = &#39;&lt;a methods=&quot;get&quot;&gt;&lt;/a&gt;&#39;;
<a name="line263"></a>
<a name="line264"></a>  goog.testing.dom.assertHtmlContentsMatch(&#39;&lt;a&gt;&lt;/a&gt;&#39;, root);
<a name="line265"></a>  goog.testing.dom.assertHtmlContentsMatch(&#39;&lt;a methods=&quot;get&quot;&gt;&lt;/a&gt;&#39;, root);
<a name="line266"></a>  goog.testing.dom.assertHtmlContentsMatch(&#39;&lt;a methods=&quot;get&quot;&gt;&lt;/a&gt;&#39;, root,
<a name="line267"></a>      true);
<a name="line268"></a>}
<a name="line269"></a>
<a name="line270"></a>function testAssertHtmlMatchesForMethodsAttribute() {
<a name="line271"></a>  root.innerHTML = &#39;&lt;input&gt;&lt;/input&gt;&#39;;
<a name="line272"></a>
<a name="line273"></a>  goog.testing.dom.assertHtmlContentsMatch(&#39;&lt;input&gt;&lt;/input&gt;&#39;, root);
<a name="line274"></a>  goog.testing.dom.assertHtmlContentsMatch(&#39;&lt;input&gt;&lt;/input&gt;&#39;, root, true);
<a name="line275"></a>}
<a name="line276"></a>
<a name="line277"></a>function testAssertHtmlMatchesForIdAttribute() {
<a name="line278"></a>  root.innerHTML = &#39;&lt;div id=&quot;foo&quot;&gt;&lt;/div&gt;&#39;;
<a name="line279"></a>
<a name="line280"></a>  goog.testing.dom.assertHtmlContentsMatch(&#39;&lt;div&gt;&lt;/div&gt;&#39;, root);
<a name="line281"></a>  goog.testing.dom.assertHtmlContentsMatch(&#39;&lt;div id=&quot;foo&quot;&gt;&lt;/div&gt;&#39;, root);
<a name="line282"></a>  goog.testing.dom.assertHtmlContentsMatch(&#39;&lt;div id=&quot;foo&quot;&gt;&lt;/div&gt;&#39;, root,
<a name="line283"></a>      true);
<a name="line284"></a>}
<a name="line285"></a>
<a name="line286"></a>function testAssertHtmlMatchesWhenIdIsNotSpecified() {
<a name="line287"></a>  root.innerHTML = &#39;&lt;div id=&quot;someId&quot;&gt;&lt;/div&gt;&#39;;
<a name="line288"></a>
<a name="line289"></a>  goog.testing.dom.assertHtmlContentsMatch(&#39;&lt;div&gt;&lt;/div&gt;&#39;, root);
<a name="line290"></a>}
<a name="line291"></a>
<a name="line292"></a>function testAssertHtmlMismatchWhenIdIsNotSpecified() {
<a name="line293"></a>  root.innerHTML = &#39;&lt;div id=&quot;someId&quot;&gt;&lt;/div&gt;&#39;;
<a name="line294"></a>
<a name="line295"></a>  var e = assertThrows(function() {
<a name="line296"></a>    goog.testing.dom.assertHtmlContentsMatch(&#39;&lt;div&gt;&lt;/div&gt;&#39;, root, true);
<a name="line297"></a>  });
<a name="line298"></a>  assertContains(&#39;Unexpected attribute with name id in element&#39;, e.message);
<a name="line299"></a>}
<a name="line300"></a>
<a name="line301"></a>function testAssertHtmlMismatchWhenIdIsSpecified() {
<a name="line302"></a>  root.innerHTML = &#39;&lt;div&gt;&lt;/div&gt;&#39;;
<a name="line303"></a>
<a name="line304"></a>  var e = assertThrows(function() {
<a name="line305"></a>    goog.testing.dom.assertHtmlContentsMatch(&#39;&lt;div id=&quot;someId&quot;&gt;&lt;/div&gt;&#39;, root);
<a name="line306"></a>  });
<a name="line307"></a>  assertContains(&#39;Expected to find attribute with name id, in element&#39;,
<a name="line308"></a>      e.message);
<a name="line309"></a>
<a name="line310"></a>  e = assertThrows(function() {
<a name="line311"></a>    goog.testing.dom.assertHtmlContentsMatch(&#39;&lt;div id=&quot;someId&quot;&gt;&lt;/div&gt;&#39;, root,
<a name="line312"></a>        true);
<a name="line313"></a>  });
<a name="line314"></a>  assertContains(&#39;Expected to find attribute with name id, in element&#39;,
<a name="line315"></a>      e.message);
<a name="line316"></a>}
<a name="line317"></a>
<a name="line318"></a>function testAssertHtmlMatchesWhenIdIsEmpty() {
<a name="line319"></a>  root.innerHTML = &#39;&lt;div&gt;&lt;/div&gt;&#39;;
<a name="line320"></a>
<a name="line321"></a>  goog.testing.dom.assertHtmlContentsMatch(&#39;&lt;div&gt;&lt;/div&gt;&#39;, root);
<a name="line322"></a>  goog.testing.dom.assertHtmlContentsMatch(&#39;&lt;div&gt;&lt;/div&gt;&#39;, root, true);
<a name="line323"></a>}
<a name="line324"></a>
<a name="line325"></a>function testAssertHtmlMatchesWithDisabledAttribute() {
<a name="line326"></a>  var disabledShortest = &#39;&lt;input disabled=&quot;disabled&quot;&gt;&#39;;
<a name="line327"></a>  var disabledShort = &#39;&lt;input disabled=&quot;&quot;&gt;&#39;;
<a name="line328"></a>  var disabledLong = &#39;&lt;input disabled=&quot;disabled&quot;&gt;&#39;;
<a name="line329"></a>  var enabled = &#39;&lt;input&gt;&#39;;
<a name="line330"></a>
<a name="line331"></a>  root.innerHTML = disabledLong;
<a name="line332"></a>  goog.testing.dom.assertHtmlContentsMatch(disabledShortest, root, true);
<a name="line333"></a>  goog.testing.dom.assertHtmlContentsMatch(disabledShort, root, true);
<a name="line334"></a>  goog.testing.dom.assertHtmlContentsMatch(disabledLong, root, true);
<a name="line335"></a>
<a name="line336"></a>
<a name="line337"></a>  var e = assertThrows(&#39;Should fail due to mismatched text&#39;, function() {
<a name="line338"></a>    goog.testing.dom.assertHtmlContentsMatch(enabled, root, true);
<a name="line339"></a>  });
<a name="line340"></a>  // Attribute value mismatch in IE.
<a name="line341"></a>  // Unexpected attribute error in other browsers.
<a name="line342"></a>  assertContains(&#39;disabled&#39;, e.message);
<a name="line343"></a>}
<a name="line344"></a>
<a name="line345"></a>function testAssertHtmlMatchesWithCheckedAttribute() {
<a name="line346"></a>  var checkedShortest = &#39;&lt;input type=&quot;radio&quot; name=&quot;x&quot; checked=&quot;checked&quot;&gt;&#39;;
<a name="line347"></a>  var checkedShort = &#39;&lt;input type=&quot;radio&quot; name=&quot;x&quot; checked=&quot;&quot;&gt;&#39;;
<a name="line348"></a>  var checkedLong = &#39;&lt;input type=&quot;radio&quot; name=&quot;x&quot; checked=&quot;checked&quot;&gt;&#39;;
<a name="line349"></a>  var unchecked = &#39;&lt;input type=&quot;radio&quot; name=&quot;x&quot;&gt;&#39;;
<a name="line350"></a>
<a name="line351"></a>  root.innerHTML = checkedLong;
<a name="line352"></a>  goog.testing.dom.assertHtmlContentsMatch(checkedShortest, root, true);
<a name="line353"></a>  goog.testing.dom.assertHtmlContentsMatch(checkedShort, root, true);
<a name="line354"></a>  goog.testing.dom.assertHtmlContentsMatch(checkedLong, root, true);
<a name="line355"></a>  if (!goog.userAgent.IE) {
<a name="line356"></a>    // CHECKED attribute is ignored because it&#39;s among BAD_IE_ATTRIBUTES_.
<a name="line357"></a>    var e = assertThrows(&#39;Should fail due to mismatched text&#39;, function() {
<a name="line358"></a>      goog.testing.dom.assertHtmlContentsMatch(unchecked, root, true);
<a name="line359"></a>    });
<a name="line360"></a>    assertContains(&#39;Unexpected attribute with name checked&#39;, e.message);
<a name="line361"></a>  }
<a name="line362"></a>}
<a name="line363"></a>
<a name="line364"></a>function testAssertHtmlMatchesWithWhitespace() {
<a name="line365"></a>  root.innerHTML = &#39;&#39;;
<a name="line366"></a>  root.appendChild(goog.dom.createTextNode(&#39;  A  &#39;));
<a name="line367"></a>  goog.testing.dom.assertHtmlContentsMatch(&#39;  A  &#39;, root);
<a name="line368"></a>
<a name="line369"></a>  root.innerHTML = &#39;&#39;;
<a name="line370"></a>  root.appendChild(goog.dom.createTextNode(&#39;  A  &#39;));
<a name="line371"></a>  root.appendChild(goog.dom.createDom(&#39;span&#39;, null, &#39;  B  &#39;));
<a name="line372"></a>  root.appendChild(goog.dom.createTextNode(&#39;  C  &#39;));
<a name="line373"></a>  goog.testing.dom.assertHtmlContentsMatch(
<a name="line374"></a>      &#39;  A  &lt;span&gt;  B  &lt;/span&gt;  C  &#39;, root);
<a name="line375"></a>
<a name="line376"></a>  root.innerHTML = &#39;&#39;;
<a name="line377"></a>  root.appendChild(goog.dom.createTextNode(&#39;  A&#39;));
<a name="line378"></a>  root.appendChild(goog.dom.createDom(&#39;span&#39;, null, &#39;  B&#39;));
<a name="line379"></a>  root.appendChild(goog.dom.createTextNode(&#39;  C&#39;));
<a name="line380"></a>  goog.testing.dom.assertHtmlContentsMatch(
<a name="line381"></a>      &#39;  A&lt;span&gt;  B&lt;/span&gt;  C&#39;, root);
<a name="line382"></a>}
<a name="line383"></a>
<a name="line384"></a>function testAssertHtmlMatchesWithWhitespaceAndNesting() {
<a name="line385"></a>  root.innerHTML = &#39;&#39;;
<a name="line386"></a>  root.appendChild(goog.dom.createDom(&#39;div&#39;, null,
<a name="line387"></a>      goog.dom.createDom(&#39;b&#39;, null, &#39;  A  &#39;),
<a name="line388"></a>      goog.dom.createDom(&#39;b&#39;, null, &#39;  B  &#39;)));
<a name="line389"></a>  root.appendChild(goog.dom.createDom(&#39;div&#39;, null,
<a name="line390"></a>      goog.dom.createDom(&#39;b&#39;, null, &#39;  C  &#39;),
<a name="line391"></a>      goog.dom.createDom(&#39;b&#39;, null, &#39;  D  &#39;)));
<a name="line392"></a>
<a name="line393"></a>  goog.testing.dom.assertHtmlContentsMatch(
<a name="line394"></a>      &#39;&lt;div&gt;&lt;b&gt;  A  &lt;/b&gt;&lt;b&gt;  B  &lt;/b&gt;&lt;/div&gt;&#39; +
<a name="line395"></a>      &#39;&lt;div&gt;&lt;b&gt;  C  &lt;/b&gt;&lt;b&gt;  D  &lt;/b&gt;&lt;/div&gt;&#39;, root);
<a name="line396"></a>
<a name="line397"></a>  root.innerHTML = &#39;&#39;;
<a name="line398"></a>  root.appendChild(goog.dom.createDom(&#39;b&#39;, null,
<a name="line399"></a>      goog.dom.createDom(&#39;b&#39;, null,
<a name="line400"></a>          goog.dom.createDom(&#39;b&#39;, null, &#39;  A  &#39;))));
<a name="line401"></a>  root.appendChild(goog.dom.createDom(&#39;b&#39;, null, &#39;  B  &#39;));
<a name="line402"></a>
<a name="line403"></a>  goog.testing.dom.assertHtmlContentsMatch(
<a name="line404"></a>      &#39;&lt;b&gt;&lt;b&gt;&lt;b&gt;  A  &lt;/b&gt;&lt;/b&gt;&lt;/b&gt;&lt;b&gt;  B  &lt;/b&gt;&#39;, root);
<a name="line405"></a>
<a name="line406"></a>  root.innerHTML = &#39;&#39;;
<a name="line407"></a>  root.appendChild(goog.dom.createDom(&#39;div&#39;, null,
<a name="line408"></a>      goog.dom.createDom(&#39;b&#39;, null,
<a name="line409"></a>          goog.dom.createDom(&#39;b&#39;, null, &#39;  A  &#39;))));
<a name="line410"></a>  root.appendChild(goog.dom.createDom(&#39;b&#39;, null, &#39;  B  &#39;));
<a name="line411"></a>
<a name="line412"></a>  goog.testing.dom.assertHtmlContentsMatch(
<a name="line413"></a>      &#39;&lt;div&gt;&lt;b&gt;&lt;b&gt;  A  &lt;/b&gt;&lt;/b&gt;&lt;/div&gt;&lt;b&gt;  B  &lt;/b&gt;&#39;, root);
<a name="line414"></a>
<a name="line415"></a>  root.innerHTML = &#39;&amp;nbsp;&#39;;
<a name="line416"></a>  goog.testing.dom.assertHtmlContentsMatch(
<a name="line417"></a>      &#39;&amp;nbsp;&#39;, root);
<a name="line418"></a>}
<a name="line419"></a>
<a name="line420"></a>function testAssertHtmlMatches() {
<a name="line421"></a>  // Since assertHtmlMatches is based on assertHtmlContentsMatch, we leave the
<a name="line422"></a>  // majority of edge case testing to the above.  Here we just do a sanity
<a name="line423"></a>  // check.
<a name="line424"></a>  goog.testing.dom.assertHtmlMatches(&#39;&lt;div&gt;abc&lt;/div&gt;&#39;, &#39;&lt;div&gt;abc&lt;/div&gt;&#39;);
<a name="line425"></a>  goog.testing.dom.assertHtmlMatches(&#39;&lt;div&gt;abc&lt;/div&gt;&#39;, &#39;&lt;div&gt;abc&lt;/div&gt; &#39;);
<a name="line426"></a>  goog.testing.dom.assertHtmlMatches(
<a name="line427"></a>      &#39;&lt;div style=&quot;font-size: 1px; color: red&quot;&gt;abc&lt;/div&gt;&#39;,
<a name="line428"></a>      &#39;&lt;div style=&quot;color: red;  font-size: 1px;;&quot;&gt;abc&lt;/div&gt;&#39;);
<a name="line429"></a>
<a name="line430"></a>  var e = assertThrows(&#39;Should fail due to mismatched text&#39;, function() {
<a name="line431"></a>    goog.testing.dom.assertHtmlMatches(&#39;&lt;div&gt;abc&lt;/div&gt;&#39;, &#39;&lt;div&gt;abd&lt;/div&gt;&#39;);
<a name="line432"></a>  });
<a name="line433"></a>  assertContains(&#39;Text should match&#39;, e.message);
<a name="line434"></a>}
</pre>


</body>
</html>
